﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TimeReporter
{
    public partial class WeeklyProjectView : UserControl
    {
        ProjectList theProjects = ProjectList.getInstance();
        //ProjectWeeklySummary theSummary = new ProjectWeeklySummary();

        
        
        public WeeklyProjectView()
        {
            InitializeComponent();

            theProjects.ListIsFilled += new myBindingListView<ProjectObject>.listIsFilled(theProjects_ListIsFilled);
            theProjects.PropertyChanged += new PropertyChangedEventHandler(theProjects_PropertyChanged);
            theProjects.ListChanged += new ListChangedEventHandler(theProjects_ListChanged);
            

            dgWeeklyProjects.AutoGenerateColumns = false;
            dgWeeklyProjects.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            //dgWeeklyProjects.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgWeeklyProjects.AllowUserToResizeColumns = false;
            dgWeeklyProjects.AllowUserToResizeRows = false;
            dgWeeklyProjects.ScrollBars = ScrollBars.Vertical;


            DataGridViewColumn c1 = new DataGridViewTextBoxColumn();
            c1.DataPropertyName = "Project";
            c1.Name = "Project";
            c1.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgWeeklyProjects.Columns.Add(c1);

            DataGridViewColumn c2 = new DataGridViewTextBoxColumn();
            c2.DataPropertyName = "Monday";
            c2.Name = "Mon";
            c2.MinimumWidth = 15;
            c2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            dgWeeklyProjects.Columns.Add(c2);

            DataGridViewColumn c3 = new DataGridViewTextBoxColumn();
            c3.DataPropertyName = "Tuesday";
            c3.Name = "Tue";
            c3.MinimumWidth = 15;
            c3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            dgWeeklyProjects.Columns.Add(c3);

            DataGridViewColumn c4 = new DataGridViewTextBoxColumn();
            c4.DataPropertyName = "Wednesday";
            c4.Name = "Wed";
            c4.MinimumWidth = 15;
            c4.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            dgWeeklyProjects.Columns.Add(c4);

            DataGridViewColumn c5 = new DataGridViewTextBoxColumn();
            c5.DataPropertyName = "Thursday";
            c5.Name = "Thu";
            c5.MinimumWidth = 15;
            c5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            dgWeeklyProjects.Columns.Add(c5);

            DataGridViewColumn c6 = new DataGridViewTextBoxColumn();
            c6.DataPropertyName = "Friday";
            c6.Name = "Fri";
            c6.MinimumWidth = 15;
            c6.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            dgWeeklyProjects.Columns.Add(c6);

            DataGridViewColumn c7 = new DataGridViewTextBoxColumn();
            c7.DataPropertyName = "Saturday";
            c7.Name = "Sat";
            c7.MinimumWidth = 15;
            c7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            dgWeeklyProjects.Columns.Add(c7);

            DataGridViewColumn c8 = new DataGridViewTextBoxColumn();
            c8.DataPropertyName = "Sunday";
            c8.Name = "Sun";
            c8.MinimumWidth = 15;
            c8.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            dgWeeklyProjects.Columns.Add(c8);
            
        }

        void theProjects_ListChanged(object sender, ListChangedEventArgs e)
        {            
            
            Console.WriteLine("List changed event type {0} ", e.ListChangedType.ToString());
            Console.WriteLine("argument {0}: ",e.PropertyDescriptor);
            
        }

        void theProjects_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Console.WriteLine("Property changed event from {0}", e.PropertyName.ToString());
        }

        void theProjects_ListIsFilled(object source)
        {
            Console.WriteLine("theProjects is filled!!");
            //theSummary.process();
            foreach (ProjectObject p in theProjects)
            {
                p.SummarizeWeek(chkUseLastWeek.Checked);
            }            
        }

        private void chkUseLastWeek_CheckedChanged(object sender, EventArgs e)
        {
           // theSummary.UsePreviousWeek = true;
           // theSummary.process();
            foreach (ProjectObject p in theProjects)
            {
                p.SummarizeWeek(chkUseLastWeek.Checked);
            }
        }

 
    }
}
